package cn.stylefeng.guns.modular.rest;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.comm.util.DateUtils;
import cn.stylefeng.guns.modular.wordstudy.entity.Favorite;
import cn.stylefeng.guns.modular.wordstudy.entity.SignHistory;
import cn.stylefeng.guns.modular.wordstudy.entity.Word;
import cn.stylefeng.guns.modular.wordstudy.model.params.StudyHistoryParam;
import cn.stylefeng.guns.modular.wordstudy.model.result.StudyHistoryResult;
import cn.stylefeng.guns.modular.wordstudy.service.FavoriteService;
import cn.stylefeng.guns.modular.wordstudy.service.SignHistoryService;
import cn.stylefeng.guns.modular.wordstudy.service.StudyHistoryService;
import cn.stylefeng.guns.modular.wordstudy.service.WordService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;


/**
 * 绑定控制器
 *
 * @author
 * @Date 2019-11-18 13:24:11
 */
@RestController
@RequestMapping("/gunsApi/sign/history")
public class ApiNeedTokenSignHistoryController extends BaseController {

    @Autowired
    private SignHistoryService signHistoryService;

    @PostMapping(value = "add")
    public Object add(SignHistory signHistory) {
        Map map = new HashMap();
        signHistory.setSignDate(new DateTime());;
        signHistoryService.save(signHistory);
        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

    @RequestMapping(value = "list")
    public Object list(String openId) {
        Map map = new HashMap();
        List<SignHistory> signHistories = signHistoryService.list(new QueryWrapper<SignHistory>().eq("open_id", openId));
        List<String> list = new ArrayList<>();
        signHistories.forEach(signHistory -> {
            list.add(DateUtils.formateYYYYMMDD(signHistory.getSignDate()));
        });
        map.put("signHistories", list);
        map.put("cnt", list.size());
        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

}


